<?php
/*
Cogumelo v0.3 - http://cogumelo.googlecode.com - Innoto S.L.
Copyright (C) 2012 Innoto Gestión para el Desarrollo Social S.L. <mapinfo@map-experience.com>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
USA.
*/

Class VO
{
	var $attributes;

	
	// set variable list (initializes entity)
	function setVarlist(array $datarray) 
	{
		// set key
		if(array_key_exists($this::$keyId, $datarray)){
			$this->setter($this::$keyId, $datarray[$this::$keyId]);
		}
	
		// rest of variables
		foreach($datarray as $datakey=>$data) {
				$this->setter($datakey, $data, true);
		}
	}
	
	
	// set a attribute. If exist a manual method use it
	function setter($setterkey, $value = false, $ignore_nonexistent_key = false)
	{
		//var_dump($value);
		if( in_array($setterkey, $this::$keys) || $setterkey == $this::$keyId)
			$this->attributes[$setterkey] = $value;
		else{
			if(!$ignore_nonexistent_key)
				Cogumelo::Error("key '". $setterkey ."' doesn't exist in VO::".$this::$objName);
		}
			
	}

	// get a attribute. If exist a manual method use it
	function getter($setterkey)
	{
		if(array_key_exists( $setterkey, $this->attributes))
			return $this->attributes[$setterkey];
		else
			return false;
	}

}
